import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//Initializes the Location of Where the inventory is taking place, and who is taking it. 
public class InventoryInit implements ActionListener{

	private JFrame locationjFrame = null;  
	private JPanel locationContentPane = null;
	private JLabel locationLabel = null;
	private JTextField locationTextField = null;
	private JButton enterButton = null;
	private JLabel userLabel = null;
	private JComboBox userComboBox = null;

	private String[] userList = {"Select User", "Coyle, Jeff", "Donaldson, Steve", "Fisher, Al" , "Fry, Peggy" };
	private JLabel titleLabel = null;

	private JFrame getLocationjFrame() {
		if (locationjFrame == null) {
			locationjFrame = new JFrame();
			locationjFrame.setSize(new Dimension(441, 223));

			locationjFrame.setContentPane(getLocationContentPane());
		}
		return locationjFrame;
	}

	private JPanel getLocationContentPane() {
		if (locationContentPane == null) {
			titleLabel = new JLabel();
			titleLabel.setBounds(new Rectangle(1, 19, 424, 39));
			titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
			titleLabel.setFont(new Font("Script MT Bold", Font.BOLD, 18));
			titleLabel.setText("The Shane Coldwater Inventory Program BETA");
			userLabel = new JLabel();
			userLabel.setBounds(new Rectangle(4, 101, 38, 16));
			userLabel.setText("User:");
			locationLabel = new JLabel();
			locationLabel.setBounds(new Rectangle(3, 72, 88, 16));
			locationLabel.setText("Enter Location:");
			locationContentPane = new JPanel();
			locationContentPane.setLayout(null);
			locationContentPane.add(locationLabel, null);
			locationContentPane.add(getLocationTextField(), null);
			locationContentPane.add(getEnterButton(), null);
			locationContentPane.add(userLabel, null);
			locationContentPane.add(getUserComboBox(), null);
			locationContentPane.add(titleLabel, null);
		}
		return locationContentPane;
	}

	private JTextField getLocationTextField() {
		if (locationTextField == null) {
			locationTextField = new JTextField();
			locationTextField.setBounds(new Rectangle(92, 71, 226, 20));
		}
		return locationTextField;
	}

	private JButton getEnterButton() {
		if (enterButton == null) {
			enterButton = new JButton();
			enterButton.setBounds(new Rectangle(325, 68, 84, 25));
			enterButton.setText("ENTER");
		}
		return enterButton;
	}

	private JComboBox getUserComboBox() {
		if (userComboBox == null) {
			userComboBox = new JComboBox(userList);
			userComboBox.setBounds(new Rectangle(56, 101, 143, 25));
		}
		return userComboBox;
	}

	private void buildGUI(){
		this.getLocationjFrame();

		locationjFrame.setVisible(true);
		locationjFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		this.enterButton.setVisible(false);
		this.enterButton.addActionListener(this);

		this.userComboBox.addActionListener(this);
	}

	public static void main(String[] args) {
		new InventoryInit().buildGUI();
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		if(arg0.getSource()== this.userComboBox){
			if(this.userComboBox.getSelectedItem() == "Select User"){
				this.enterButton.setVisible(false);
			}
			else{
				this.enterButton.setVisible(true);
			}
		}

		if(arg0.getSource() == this.enterButton){

			new VisualInventory(locationTextField.getText(), this.getUserComboBox().getSelectedItem().toString());

		}
	}
}
